package com.bbs.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bbs.biz.UserBiz;
import com.bbs.biz.impl.UserBizImpl;

public class RegisterServlet extends HttpServlet {


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
        
		doPost(request,response);
	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
        String registername= request.getParameter("registername");
        String registerpassword=request.getParameter("registerpassword");       
        String registerpassword2=request.getParameter("registerpassword2");
        String email=request.getParameter("email");
        UserBiz userbiz=new UserBizImpl();
        try {
			if(registerpassword.equals(registerpassword2)&&userbiz.register(registername, registerpassword, email)){       	
				RequestDispatcher dispatcher=request.getRequestDispatcher("login.jsp");
				dispatcher.forward(request, response);
			}
			else{
				
			     
				RequestDispatcher dispatcher=request.getRequestDispatcher("register.jsp");
				dispatcher.forward(request, response);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
